package com.boang.controller;

import com.boang.common.Result;
import com.boang.po.User;
import com.boang.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/{id}")
    public User findById(@PathVariable Integer id) {
        User user = userService.getById(id);
        return user;
    }

    @PostMapping("/add")
    public Result add(@RequestBody User user) {
        userService.addOne(user);
        return new Result().success();
    }

    @GetMapping("/list")
    public Result list() {
        List<User> userList = userService.list();
        return Result.success(userList);
    }

}
